home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / netconf / simple.c < prev    next >
C/C++ Source or Header  |  1996-03-09  |  6KB  |  193 lines

  1. #include <string.h>
  2. #include "netconf.h"
  3. #include "../dialog/dialog.h"
  4. #include "../xconf/xconf.h"
  5. #include "../paths.h"
  6. #include "netconf.m"
  7.  
  8. #ifdef TEST
  9.     #undef ETC_NETWORKS
  10.     #undef ETC_HOSTS
  11.     #define ETC_HOSTS         "/tmp/hosts"
  12.     #define ETC_NETWORKS     "/tmp/networks"
  13. #endif
  14.  
  15. static NETCONF_HELP_FILE help_simple ("simple");
  16.  
  17. /*
  18.     Check if there is not already some network configured.
  19.     Return -1 if the installation can't be done.
  20. */
  21. static int simple_check()
  22. {
  23.     int ret = -1;
  24.     /* #todo: netconf / simple setup
  25.         before doing a simple networking installation from
  26.         scratch, we should check there is no valid configuration
  27.         or at least do backup of the files which will be modified.
  28.     */
  29.     char intro[1000];
  30.     sprintf (intro,MSG_U(I_SIMPLEINST
  31.         ,"This option allows you to install\n"
  32.          "a complete network setup, including the names\n"
  33.          "of all machine.\n"
  34.          "\n"
  35.          "This will overwrite the following files:\n"
  36.          "      %s\n"
  37.          "      %s\n")
  38.         ,ETC_HOSTS,ETC_NETWORKS);
  39.     if (xconf_yesno(MSG_U(Q_SIMPLEINST,"Installing network from scratch")
  40.         ,intro
  41.         ,help_simple)==MENU_YES){
  42.         ret = 0;
  43.     }
  44.     return ret;
  45. }
  46. /* #Specification: netconf / simple setup / preselected host name
  47.     When configuring a Linux workstation using the simple
  48.     predefined network setup, all the name in the class C
  49.     network are predefined. I have tried to use funny
  50.     politically correct name :-)
  51.  
  52.     Also, each host has an alias which is simply its network
  53.     node number with the "linux-" prefix. For example, the
  54.     machine "orange" with IP number 192.168.1.5 has the
  55.     alias "linux-5".
  56.  
  57.     The number 192.168.1 is an official number that will never
  58.     be routed on the internet. So it is safe to use it even if you
  59.     get hook to the internet one day. Off course, you local network
  60.     won't be visible from the internet, but at least no internet
  61.     site will clash with one of your local machine.
  62. */
  63. /* #Specification: netconf / simple setup / preselected server
  64.     The IP number 192.168.1.1 is allocated to the machine linux-serv.
  65.  
  66.     If one machine of the network is more important that others
  67.     (supports printer, or NFS volume, or NIS, it is a good
  68.     idea to use this IP and use "linux-serv" all around your
  69.     net to refer to this server.    
  70. */
  71. /* #Specification: netconf / simple setup / out of gas
  72.     I was not able to produce 253 different funny/simple host
  73.     name. Anyway a simple network with 200 or more machine
  74.     in it, is not a simple network.
  75. */
  76. // Let see if I do have some culture. The goal is to setup
  77. // 253 funny names. I will start with fruits and vegetable
  78. // and see how far I can go... For the record, I am french
  79. // speaking.
  80. // The names must be short and easy to type
  81. static int nbname;
  82. static const char **tb;
  83. /*
  84.     Select the name of your machine from a list
  85. */
  86. static int simple_select ()
  87. {
  88.     // Because of a restriction with the translation system, _tb[]
  89.     // which should be declared outside of this function is declared
  90.     // here as _tb and tb is declared as a pointer.
  91.     static const char *_tb[]={
  92.         MSG_U(DUMMY_NAME_SERV,"linux-serv"),
  93.         // Fruits section
  94.         MSG_U(DUMMY_NAME_BANANA,"banana"),
  95.         MSG_U(DUMMY_NAME_APPLE,"apple"),
  96.         MSG_U(DUMMY_NAME_CHERRY,"cherry"),
  97.         MSG_U(DUMMY_NAME_ORANGE,"orange"),
  98.         // Animals section
  99.         MSG_U(DUMMY_NAME_WOLF,"wolf"),
  100.         MSG_U(DUMMY_NAME_LION,"lion"),
  101.         MSG_U(DUMMY_NAME_MOUSE,"mouse"),
  102.         MSG_U(DUMMY_NAME_EAGLE,"eagle"),
  103.         MSG_U(DUMMY_NAME_COBRA,"cobra"),
  104.         // Known persons (real or not) section
  105.         MSG_U(DUMMY_NAME_ELVIS,"elvis"),
  106.         MSG_U(DUMMY_NAME_BABE,"babe"),
  107.         MSG_U(DUMMY_NAME_ALNOLD,"arnold"),
  108.         MSG_U(DUMMY_NAME_ROCKY,"rocky"),
  109.         MSG_U(DUMMY_NAME_BOND,"bond"),
  110.         MSG_U(DUMMY_NAME_RINGO,"ringo"),
  111.         MSG_U(DUMMY_NAME_PAUL,"paul"),
  112.         MSG_U(DUMMY_NAME_JOHN,"john"),
  113.         MSG_U(DUMMY_NAME_GEORGE,"george"),
  114.         MSG_U(DUMMY_NAME_MADONA,"madona"),
  115.         MSG_U(DUMMY_NAME_TARZAN,"tarzan"),
  116.         MSG_U(DUMMY_NAME_LINUS,"linus"),
  117.         // Some countries
  118.         MSG_U(DUMMY_NAME_CANADA,"canada"),
  119.         MSG_U(DUMMY_NAME_USA,"usa"),
  120.         MSG_U(DUMMY_NAME_FINLAND,"finland"),
  121.         MSG_U(DUMMY_NAME_FRANCE,"france"),
  122.     };
  123.     tb = _tb;
  124.     nbname = sizeof(_tb)/sizeof(_tb[0]);
  125.     const char *menuopt[nbname*2+1];
  126.     int ii=0;
  127.     for (int i=0; i<nbname; i++){
  128.         menuopt[ii++] = " ";
  129.         menuopt[ii++] = tb[i];
  130.     }
  131.     menuopt[ii] = NULL;
  132.     int choice=0;
  133.     MENU_STATUS code = xconf_menu (MSG_U(T_YOURMACHINE,"Your machine name")
  134.         ,MSG_U(I_YOURMACHINE,"You must select a name for your machine\n"
  135.          "out of this list. Each of your co-networker\n"
  136.          "must select a different name\n")
  137.         ,help_simple
  138.         ,menuopt,choice);
  139.     if (code == MENU_ESCAPE || code == MENU_QUIT){
  140.         choice = -1;
  141.     }
  142.     return choice;
  143. }
  144.  
  145. static int simple_setup()
  146. {
  147.     int loghost = simple_select ();
  148.     int ret = -1;
  149.     if (loghost != -1){
  150.         HOSTS hosts;
  151.         NETWORKS networks;
  152.         hosts.delall();
  153.         networks.delall();
  154.         for (int i=0; i<nbname; i++){
  155.             char buf[100];
  156.             sprintf (buf,"192.168.1.%d %s linux-%d",i+1,tb[i],i+1);
  157.             if (i == loghost) strcat (buf," loghost");
  158.             hosts.add (buf);
  159.         }
  160.         networks.add ("eth0_network 192.168.1.0");
  161.         hosts.write ();
  162.         networks.write ();
  163.         ret = 0;
  164.     }
  165.     return ret;
  166. }
  167. void simple_install()
  168. {
  169.     /* #SpΘcification: netconf / install a simple network
  170.         netconf can install a simple tcp/ip from scratch. After
  171.         informing the user properly, it proceed and create all
  172.         the entries for a class C network. After that, the user
  173.         only select the name of his machine out of a predefined
  174.         list.
  175.     */
  176.     if (simple_check()!=-1
  177.         && simple_setup()!=-1){
  178.     }    
  179. }
  180.  
  181. #ifdef TEST
  182.  
  183. int main (int argc, char *argv[])
  184. {
  185.     init_dialog();
  186.     simple_install();
  187.     endwin();
  188.     return 0;
  189. }
  190.  
  191. #endif
  192.  
  193.